/****************************************************************************
**
** CreateCharacterSelectionGump.cpp
**
** Copyright (C) August 2014 Hotride
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
*****************************************************************************
*/
//---------------------------------------------------------------------------
#include "stdafx.h"
//---------------------------------------------------------------------------
TCreateCharacterSelectionGump::TCreateCharacterSelectionGump()
{
}
//---------------------------------------------------------------------------
TCreateCharacterSelectionGump::~TCreateCharacterSelectionGump()
{
}
//---------------------------------------------------------------------------
void TCreateCharacterSelectionGump::Init()
{
	UO->m_Profession->m_ScrollHeight = 0.0f;
	UO->m_UsedProfessionCategory = UO->m_Profession;
	UO->m_UsedProfession = NULL;
}
//---------------------------------------------------------------------------
int TCreateCharacterSelectionGump::Render(bool mode)
{
	DWORD ticks = GetTickCount();

	if (g_LastRenderTime > ticks)
	{
		if (mode || !g_SelectGumpObjects) return 0;
	}

	if (mode)
	{
		int CanSelectedButton = g_LastSelectedObject;

		int CanPressedButton = 0;
		if (g_LeftMouseDown && g_LastObjectLeftMouseDown == g_LastSelectedObject) CanPressedButton = g_LastObjectLeftMouseDown;
	
		g_LastRenderTime = ticks + g_FrameDelay;

		UO->m_GL.BeginDraw();
		
		UO->DrawGump(0x0588, 0, 0, 0, 640, 480); //Main Gump background
		UO->DrawGump(0x157C, 0, 0, 0); //Main Gump
		UO->DrawGump(0x15A0, 0, 0, 4); //Main Gump Notes
		
		WORD GumpID = 0x1589 + (int)(CanSelectedButton == 1); //X gump /lighted
		if (CanPressedButton == 1) GumpID = 0x158B; //X gump (pressed)
		UO->DrawGump(GumpID, 0, 555, 4);
		
		GumpID = 0x15A1 + (int)(CanSelectedButton == 2); //< gump /lighted
		if (CanPressedButton == 2) GumpID = 0x15A3; //< gump pressed
		UO->DrawGump(GumpID, 0, 586, 445); //< gump

		UO->DrawResizepicGump(0xA28, 80, 80, 546, 352); //Character profeccion selection field
		
		UO->DrawGump(0x058B, 0, 145, 57); //Create character header
		UO->DrawGump(0x0589, 0, 222, 44); //Label container
		
		GumpID = 0x119C + (int)(CanSelectedButton == 2); //Arrow < /lighted
		if (CanPressedButton == 4) GumpID = 0x119E; //Arrow < pressed
		UO->DrawGump(GumpID, 0, 200, 356); //Arrow <
		


		UO->DrawResizepicGump(0xBB8, 120, 137, 204, 214); //Description text field


		
		//Text in box
		UO->m_GL.ViewPort(125, 141, 195, 206);

		if (UO->m_UsedProfessionCategory != NULL)
		{
			if (UO->m_UsedProfessionCategory == UO->m_Profession)
			{
				UO->m_GL.Draw(UO->m_UsedProfessionCategory->m_TextureDescription.Texture, 125, 141, UO->m_UsedProfessionCategory->m_TextureDescription.Width, UO->m_UsedProfessionCategory->m_TextureDescription.Height);
			}
			else
			{
				int HOffs = UO->m_UsedProfessionCategory->m_TextureName.Height;
				UO->m_GL.Draw(UO->m_UsedProfessionCategory->m_TextureName.Texture, 125, 141, UO->m_UsedProfessionCategory->m_TextureName.Width, UO->m_UsedProfessionCategory->m_TextureName.Height);
				UO->m_GL.Draw(UO->m_UsedProfessionCategory->m_TextureDescription.Texture, 125, 141 + HOffs, UO->m_UsedProfessionCategory->m_TextureDescription.Width, UO->m_UsedProfessionCategory->m_TextureDescription.Height);
			}
		}
		else if (UO->m_UsedProfession != NULL)
		{
			int HOffs = UO->m_UsedProfession->m_TextureName.Height;
			UO->m_GL.Draw(UO->m_UsedProfession->m_TextureName.Texture, 125, 141, UO->m_UsedProfession->m_TextureName.Width, UO->m_UsedProfession->m_TextureName.Height);
			UO->m_GL.Draw(UO->m_UsedProfession->m_TextureDescription.Texture, 125, 141 + HOffs, UO->m_UsedProfession->m_TextureDescription.Width, UO->m_UsedProfession->m_TextureDescription.Height);
		}

		UO->m_GL.RestorePort();
		


		//Description scroll bar:
		UO->DrawGump(0x00FF, 0, 324, 140); //^ background
		UO->DrawGump(0x0100, 0, 324, 169, 0, 170); //background
		UO->DrawGump(0x00FA, 0, 324, 137); //^
		UO->DrawGump(0x00FE, 0, 325, 158); //bar
		UO->DrawGump(0x00FC, 0, 324, 330); //v
		
		if (UO->m_UsedProfessionCategory != NULL)
		{
			GumpID = UO->m_UsedProfessionCategory->GetGump();
			UO->DrawGump(GumpID, 0, 231, 53); //Label gump
			float OffsY = 0.0f;
			if (UO->m_UsedProfessionCategory->m_CatChildCount > 0)
			{
				for (int i = 0; i < UO->m_UsedProfessionCategory->m_CatChildCount; i++)
				{
					UO->DrawGump(0x0589, 0, 500, 100 + OffsY); //Label container
					GumpID = UO->m_UsedProfessionCategory->m_CatChild[i]->GetGump();
					if (CanPressedButton == 6 + i) GumpID++;

					UO->DrawGump(GumpID, 0, 509, 109 + OffsY); //Label gump
					UO->m_Font->DrawA(9, UO->m_UsedProfessionCategory->m_CatChild[i]->GetName().c_str(), 0x1, 350, 135 + OffsY);
					OffsY += 79.0f;
				}
			}
			if (UO->m_UsedProfessionCategory->m_ProfChildCount > 0)
			{
				for (int i = 0; i < UO->m_UsedProfessionCategory->m_ProfChildCount; i++)
				{
					UO->DrawGump(0x0589, 0, 500, 100 + OffsY); //Label container
					GumpID = UO->m_UsedProfessionCategory->m_ProfChild[i]->GetGump();
					if (CanPressedButton == 6 + i + UO->m_UsedProfessionCategory->m_CatChildCount) GumpID++;

					UO->DrawGump(GumpID, 0, 509, 109 + OffsY); //Label gump
					UO->m_Font->DrawA(9, UO->m_UsedProfessionCategory->m_ProfChild[i]->GetName().c_str(), 0x1, 350, 135 + OffsY);
					OffsY += 79.0f;
				}
			}
		}
		else if (UO->m_UsedProfession != NULL)
		{
			UO->DrawGump(UO->m_UsedProfession->GetGump(), 0, 231, 53); //Label gump
			
			const float SphereListWidth = 95.0f;
			float ValPer = 0.0f;
			
			//Stats
			if (g_LastObjectLeftMouseDown >= 6 && g_LastObjectLeftMouseDown <= 8)
			{
				float MX = ((float)g_MouseX - 500.0f);
				if (MX < 0) MX = 0.0f;
				if (MX > 95) MX = 95.0f;

				ValPer = ((float)MX / 95.0f) * 100.0f;
				ValPer = (35.0f * ValPer) / 100.0f;
				if (ValPer < 0) ValPer = 0.0f;

				int stats[3] = {UO->m_UsedProfession->GetStr(), UO->m_UsedProfession->GetDex(), UO->m_UsedProfession->GetInt()};

				int used_stat = g_LastObjectLeftMouseDown - 6;
				int others_stat[2] = {0};

				others_stat[0] = 0;
				if (others_stat[0] == used_stat) others_stat[0]++;

				others_stat[1] = others_stat[0] + 1;
				if (others_stat[1] == used_stat) others_stat[1]++;

				stats[used_stat] = 10 + ValPer;

				int stat_sum = 65 - (stats[0] + stats[1] + stats[2]);

				if (stat_sum > 0) //stat will decrease
				{
					while (stat_sum > 0)
					{
						if (stats[others_stat[0]] < 45)
						{
							stat_sum--;
							stats[others_stat[0]]++;
						}
						else if (stats[others_stat[1]] < 45)
						{
							stat_sum--;
							stats[others_stat[1]]++;
						}
						else break;
					}
				}
				else if (stat_sum < 0) //stat will increase
				{
					while (stat_sum < 0)
					{
						if (stats[others_stat[0]] > 10)
						{
							stat_sum++;
							stats[others_stat[0]]--;
						}
						else if (stats[others_stat[1]] > 10)
						{
							stat_sum++;
							stats[others_stat[1]]--;
						}
						else break;
					}
				}
				UO->m_UsedProfession->SetStr(stats[0]);
				UO->m_UsedProfession->SetDex(stats[1]);
				UO->m_UsedProfession->SetInt(stats[2]);
			}

			//Skills
			if (g_LastObjectLeftMouseDown >= 9 && g_LastObjectLeftMouseDown <= 11)
			{
				float MX = ((float)g_MouseX - 500.0f);
				if (MX < 0) MX = 0.0f;
				if (MX > 95) MX = 95.0f;

				ValPer = ((float)MX / 95.0f) * 100.0f;
				ValPer = (50.0f * ValPer) / 100.0f;
				if (ValPer < 0) ValPer = 0.0f;
				
				int skills[3] = {UO->m_UsedProfession->GetSkillValue(0), UO->m_UsedProfession->GetSkillValue(1), UO->m_UsedProfession->GetSkillValue(2)};

				int used_skill = g_LastObjectLeftMouseDown - 9;
				int others_skills[2] = {0};

				others_skills[0] = 0;
				if (others_skills[0] == used_skill) others_skills[0]++;

				others_skills[1] = others_skills[0] + 1;
				if (others_skills[1] == used_skill) others_skills[1]++;

				skills[used_skill] = ValPer;

				int skills_sum = 100 - (skills[0] + skills[1] + skills[2]);
				
				if (skills_sum > 0) //skill will decrease
				{
					while (skills_sum > 0)
					{
						if (skills[others_skills[0]] < 50)
						{
							skills_sum--;
							skills[others_skills[0]]++;
						}
						else if (skills[others_skills[1]] < 50)
						{
							skills_sum--;
							skills[others_skills[1]]++;
						}
						else break;
					}
				}
				else if (skills_sum < 0) //skill will increase
				{
					while (skills_sum < 0)
					{
						if (skills[others_skills[0]] > 0)
						{
							skills_sum++;
							skills[others_skills[0]]--;
						}
						else if (skills[others_skills[1]] > 0)
						{
							skills_sum++;
							skills[others_skills[1]]--;
						}
						else break;
					}
				}
				UO->m_UsedProfession->SetSkillValue(0, skills[0]);
				UO->m_UsedProfession->SetSkillValue(1, skills[1]);
				UO->m_UsedProfession->SetSkillValue(2, skills[2]);
			}

			char val[10] = {0};
			UO->m_Font->DrawA(1, "Strength", 1, 360, 136);
			sprintf(val, "%d", UO->m_UsedProfession->GetStr());
			UO->m_Font->DrawA(1, val, 1, 460, 136);
			UO->DrawGump(0x00D5, 0, 500, 136); //Sphere line gump start
			UO->DrawGump(0x00D7, 0, 588, 136); //Sphere line gump end
			UO->DrawGump(0x00D6, 0, 513, 136, 75, 0); //Sphere line gump body

			ValPer = (((float)UO->m_UsedProfession->GetStr() - 10.0f) / 35.0f) * 100.0f;
			ValPer = (SphereListWidth * ValPer) / 100.0f;
			if (ValPer < 0) ValPer = 0.0f;
			UO->DrawGump(0x00D8, 0, 500 + ValPer, 136); //Sphere gump



			UO->m_Font->DrawA(1, "Dexterity", 1, 360, 166);
			sprintf(val, "%d", UO->m_UsedProfession->GetDex());
			UO->m_Font->DrawA(1, val, 1, 460, 166);
			UO->DrawGump(0x00D5, 0, 500, 166); //Sphere line gump start
			UO->DrawGump(0x00D7, 0, 588, 166); //Sphere line gump end
			UO->DrawGump(0x00D6, 0, 513, 166, 75, 0); //Sphere line gump body
			
			ValPer = (((float)UO->m_UsedProfession->GetDex() - 10.0f) / 35.0f) * 100.0f;
			ValPer = (SphereListWidth * ValPer) / 100.0f;
			if (ValPer < 0) ValPer = 0.0f;
			UO->DrawGump(0x00D8, 0, 500 + ValPer, 166); //Sphere gump



			UO->m_Font->DrawA(1, "Intelligence", 1, 360, 196);
			sprintf(val, "%d", UO->m_UsedProfession->GetInt());
			UO->m_Font->DrawA(1, val, 1, 460, 196);
			UO->DrawGump(0x00D5, 0, 500, 196); //Sphere line gump start
			UO->DrawGump(0x00D7, 0, 588, 196); //Sphere line gump end
			UO->DrawGump(0x00D6, 0, 513, 196, 75, 0); //Sphere line gump body
			
			ValPer = (((float)UO->m_UsedProfession->GetInt() - 10.0f) / 35.0f) * 100.0f;
			ValPer = (SphereListWidth * ValPer) / 100.0f;
			if (ValPer < 0) ValPer = 0.0f;
			UO->DrawGump(0x00D8, 0, 500 + ValPer, 196); //Sphere gump

			if (UO->m_UsedProfession->GetDefName() != string("advanced"))
			{
				int SkillID = UO->m_UsedProfession->GetSkillID(0);
				if (SkillID >= UO->m_SkillsCount) SkillID = 0;
				UO->m_Font->DrawA(1, UO->m_Skills[SkillID].m_Name.c_str(), 1, 360, 260, 90.0f, TS_FIXED);
				sprintf(val, "%d", UO->m_UsedProfession->GetSkillValue(0));
				UO->m_Font->DrawA(1, val, 1, 460, 260);

				SkillID = UO->m_UsedProfession->GetSkillID(1);
				if (SkillID >= UO->m_SkillsCount) SkillID = 0;
				UO->m_Font->DrawA(1, UO->m_Skills[SkillID].m_Name.c_str(), 1, 360, 292, 90.0f, TS_FIXED);
				sprintf(val, "%d", UO->m_UsedProfession->GetSkillValue(1));
				UO->m_Font->DrawA(1, val, 1, 460, 292);

				SkillID = UO->m_UsedProfession->GetSkillID(2);
				if (SkillID >= UO->m_SkillsCount) SkillID = 0;
				UO->m_Font->DrawA(1, UO->m_Skills[SkillID].m_Name.c_str(), 1, 360, 324, 90.0f, TS_FIXED);
				sprintf(val, "%d", UO->m_UsedProfession->GetSkillValue(2));
				UO->m_Font->DrawA(1, val, 1, 460, 324);
			}
			else
			{
				UO->DrawResizepicGump(0xBB8, 350, 256, 105, 25); //Skill Name text field
				int SkillID = UO->m_UsedProfession->GetSkillID(0);
				if (SkillID >= UO->m_SkillsCount) UO->m_Font->DrawA(9, "Click here", 1, 354, 261, 90.0f, TS_FIXED);
				else UO->m_Font->DrawA(9, UO->m_Skills[SkillID].m_Name.c_str(), 1, 354, 261, 90.0f, TS_FIXED);
				sprintf(val, "%d", UO->m_UsedProfession->GetSkillValue(0));
				UO->m_Font->DrawA(1, val, 1, 460, 260);
				
				UO->DrawResizepicGump(0xBB8, 350, 287, 105, 25); //Skill Name text field
				SkillID = UO->m_UsedProfession->GetSkillID(1);
				if (SkillID >= UO->m_SkillsCount) UO->m_Font->DrawA(9, "Click here", 1, 354, 292, 90.0f, TS_FIXED);
				else UO->m_Font->DrawA(9, UO->m_Skills[SkillID].m_Name.c_str(), 1, 354, 292, 90.0f, TS_FIXED);
				sprintf(val, "%d", UO->m_UsedProfession->GetSkillValue(1));
				UO->m_Font->DrawA(1, val, 1, 460, 292);
				
				UO->DrawResizepicGump(0xBB8, 350, 319, 105, 25); //Skill Name text field
				SkillID = UO->m_UsedProfession->GetSkillID(2);
				if (SkillID >= UO->m_SkillsCount) UO->m_Font->DrawA(9, "Click here", 1, 354, 325, 90.0f, TS_FIXED);
				else UO->m_Font->DrawA(9, UO->m_Skills[SkillID].m_Name.c_str(), 1, 354, 325, 90.0f, TS_FIXED);
				sprintf(val, "%d", UO->m_UsedProfession->GetSkillValue(2));
				UO->m_Font->DrawA(1, val, 1, 460, 324);
			}

			//Skill 1
			UO->DrawGump(0x00D5, 0, 500, 258); //Sphere line gump start
			UO->DrawGump(0x00D7, 0, 588, 258); //Sphere line gump end
			UO->DrawGump(0x00D6, 0, 513, 258, 75, 0); //Sphere line gump body

			ValPer = ((float)UO->m_UsedProfession->GetSkillValue(0) / 50.0f) * 100.0f;
			ValPer = (SphereListWidth * ValPer) / 100.0f;
			if (ValPer < 0) ValPer = 0.0f;
			UO->DrawGump(0x00D8, 0, 500 + ValPer, 258); //Sphere gump
			
			//Skill 2
			UO->DrawGump(0x00D5, 0, 500, 292); //Sphere line gump start
			UO->DrawGump(0x00D7, 0, 588, 292); //Sphere line gump end
			UO->DrawGump(0x00D6, 0, 513, 292, 75, 0); //Sphere line gump body

			ValPer = ((float)UO->m_UsedProfession->GetSkillValue(01) / 50.0f) * 100.0f;
			ValPer = (SphereListWidth * ValPer) / 100.0f;
			if (ValPer < 0) ValPer = 0.0f;
			UO->DrawGump(0x00D8, 0, 500 + ValPer, 292); //Sphere gump
			
			//Skill 3
			UO->DrawGump(0x00D5, 0, 500, 324); //Sphere line gump start
			UO->DrawGump(0x00D7, 0, 588, 324); //Sphere line gump end
			UO->DrawGump(0x00D6, 0, 513, 324, 75, 0); //Sphere line gump body

			ValPer = ((float)UO->m_UsedProfession->GetSkillValue(2) / 50.0f) * 100.0f;
			ValPer = (SphereListWidth * ValPer) / 100.0f;
			if (ValPer < 0) ValPer = 0.0f;
			UO->DrawGump(0x00D8, 0, 500 + ValPer, 324); //Sphere gump

			GumpID = 0x15A4 + (int)(CanSelectedButton == 3);
			if (CanPressedButton == 3) GumpID = 0x15A6; //> gump pressed
			UO->DrawGump(GumpID, 0, 610, 445); //> gump
		}

		UO->DrawCursor(0x2073); //Main Gump mouse cursor
		
		UO->m_GL.EndDraw();
	}
	else
	{
		g_LastSelectedObject = 0;
		g_LastObjectType = SOT_NO_OBJECT;

		if (UO->GumpPixelsInXY(0x1589, 555, 4))
		{
			g_LastSelectedObject = 1; //X gump
		}

		if (UO->GumpPixelsInXY(0x15A1, 586, 445))
		{
			g_LastSelectedObject = 2; //< gump
		}

		if (UO->GumpPixelsInXY(0x119C, 200, 356))
		{
			g_LastSelectedObject = 4; //Arrow <
		}

		if (UO->m_UsedProfessionCategory != NULL)
		{
			if (UO->GumpPixelsInXY(UO->m_UsedProfessionCategory->GetGump(), 231, 53))
			{
				g_LastSelectedObject = 5; //Label gump
			}

			float OffsY = 0.0f;
			if (UO->m_UsedProfessionCategory->m_CatChildCount > 0)
			{
				for (int i = 0; i < UO->m_UsedProfessionCategory->m_CatChildCount; i++)
				{
					if (UO->GumpPixelsInXY(UO->m_UsedProfessionCategory->m_CatChild[i]->GetGump(), 509, 109 + OffsY))
					{
						g_LastSelectedObject = 6 + i; //Label gump
					}
					OffsY += 79.0f;
				}
			}
			if (UO->m_UsedProfessionCategory->m_ProfChildCount > 0)
			{
				for (int i = 0; i < UO->m_UsedProfessionCategory->m_ProfChildCount; i++)
				{
					if (UO->GumpPixelsInXY(UO->m_UsedProfessionCategory->m_ProfChild[i]->GetGump(), 509, 109 + OffsY))
					{
						g_LastSelectedObject = 6 + i + UO->m_UsedProfessionCategory->m_CatChildCount; //Label gump
					}
					OffsY += 79.0f;
				}
			}
		}
		else if (UO->m_UsedProfession != NULL)
		{
			if (UO->GumpPixelsInXY(UO->m_UsedProfession->GetGump(), 231, 53))
			{
				g_LastSelectedObject = 5; //Label gump
			}
			
			if (UO->GumpPixelsInXY(0x15A4, 610, 445))
			{
				g_LastSelectedObject = 3; //> gump
			}
			
			const float SphereListWidth = 95.0f;
			float ValPer = 0.0f;

			ValPer = (((float)UO->m_UsedProfession->GetStr() - 10.0f) / 35.0f) * 100.0f;
			ValPer = (SphereListWidth * ValPer) / 100.0f;
			if (ValPer < 0) ValPer = 0.0f;
			if (UO->GumpPixelsInXY(0x00D8, 500 + ValPer, 136))
			{
				g_LastSelectedObject = 6; //Sphere gump (str)
			}

			ValPer = (((float)UO->m_UsedProfession->GetDex() - 10.0f) / 35.0f) * 100.0f;
			ValPer = (SphereListWidth * ValPer) / 100.0f;
			if (ValPer < 0) ValPer = 0.0f;
			if (UO->GumpPixelsInXY(0x00D8, 500 + ValPer, 166))
			{
				g_LastSelectedObject = 7; //Sphere gump (dex)
			}

			ValPer = (((float)UO->m_UsedProfession->GetInt() - 10.0f) / 35.0f) * 100.0f;
			ValPer = (SphereListWidth * ValPer) / 100.0f;
			if (ValPer < 0) ValPer = 0.0f;
			if (UO->GumpPixelsInXY(0x00D8, 500 + ValPer, 196))
			{
				g_LastSelectedObject = 8; //Sphere gump (int)
			}

			
			ValPer = ((float)UO->m_UsedProfession->GetSkillValue(0) / 50.0f) * 100.0f;
			ValPer = (SphereListWidth * ValPer) / 100.0f;
			if (ValPer < 0) ValPer = 0.0f;
			if (UO->GumpPixelsInXY(0x00D8, 500 + ValPer, 258))
			{
				g_LastSelectedObject = 9; //Sphere gump (skill 1)
			}

			ValPer = ((float)UO->m_UsedProfession->GetSkillValue(1) / 50.0f) * 100.0f;
			ValPer = (SphereListWidth * ValPer) / 100.0f;
			if (ValPer < 0) ValPer = 0.0f;
			if (UO->GumpPixelsInXY(0x00D8, 500 + ValPer, 292))
			{
				g_LastSelectedObject = 10; //Sphere gump (skill 2)
			}
			
			ValPer = ((float)UO->m_UsedProfession->GetSkillValue(2) / 50.0f) * 100.0f;
			ValPer = (SphereListWidth * ValPer) / 100.0f;
			if (ValPer < 0) ValPer = 0.0f;
			if (UO->GumpPixelsInXY(0x00D8, 500 + ValPer, 324))
			{
				g_LastSelectedObject = 11; //Sphere gump (skill 3)
			}
		}

		return g_LastSelectedObject;
	}
	return 0;
}
//---------------------------------------------------------------------------
void TCreateCharacterSelectionGump::ParseLeftMouseDown()
{
	Render(false);

	g_DroppedLeftMouseX = g_MouseX;
	g_DroppedLeftMouseY = g_MouseY;
	g_LeftMouseDown = true;
	g_LastObjectLeftMouseDown = g_LastSelectedObject;
}
//---------------------------------------------------------------------------
void TCreateCharacterSelectionGump::ParseLeftMouseUp()
{
	Render(false);
	g_LeftMouseDown = false;
	g_DroppedLeftMouseX = 0;
	g_DroppedLeftMouseY = 0;

	if (g_LastSelectedObject == 0 || g_LastSelectedObject != g_LastObjectLeftMouseDown)
	{
		g_LastObjectLeftMouseDown = 0;
		return;
	}

	if (g_LastObjectLeftMouseDown == 1) //x button
	{
		PostQuitMessage(0);
		if (UO != NULL) delete UO;
		UO = NULL;
		return;
	}
	else if (g_LastObjectLeftMouseDown == 2) //< button
	{
		UO->InitGump(GS_CHARACTER);
	}
	else if (g_LastObjectLeftMouseDown == 3) //> button
	{
		UO->InitGump(GS_CREATE);
	}
	else if (g_LastObjectLeftMouseDown == 4 || g_LastObjectLeftMouseDown == 5) //Arrow < or General Label gump
	{
		if (UO->m_UsedProfessionCategory != NULL)
		{
			if (UO->m_UsedProfessionCategory->m_Parent != NULL)
			{
				UO->m_UsedProfessionCategory = UO->m_UsedProfessionCategory->m_Parent;
				UO->m_UsedProfessionCategory->m_ScrollHeight = 0.0f;
				UO->m_UsedProfession = NULL;
				g_LastObjectLeftMouseDown = 0;
				return;
			}
		}
		else if (UO->m_UsedProfession != NULL)
		{
			if (UO->m_UsedProfession->m_Parent != NULL)
			{
				UO->m_UsedProfessionCategory = UO->m_UsedProfession->m_Parent;
				UO->m_UsedProfessionCategory->m_ScrollHeight = 0.0f;
				UO->m_UsedProfession = NULL;
				g_LastObjectLeftMouseDown = 0;
				return;
			}
		}

		UO->m_UsedProfessionCategory = UO->m_Profession;
	}
	else if (UO->m_UsedProfessionCategory != NULL)
	{
		float OffsY = 0.0f;

		if (UO->m_UsedProfessionCategory->m_CatChildCount > 0)
		{
			for (int i = 0; i < UO->m_UsedProfessionCategory->m_CatChildCount; i++)
			{
				if (g_LastObjectLeftMouseDown == 6 + i)
				{
					UO->m_UsedProfessionCategory = UO->m_UsedProfessionCategory->m_CatChild[i];
					UO->m_UsedProfessionCategory->m_ScrollHeight = 0.0f;
					UO->m_UsedProfession = NULL;
					g_LastObjectLeftMouseDown = 0;
					return;
				}
				OffsY += 79.0f;
			}
		}

		if (UO->m_UsedProfessionCategory->m_ProfChildCount > 0)
		{
			for (int i = 0; i < UO->m_UsedProfessionCategory->m_ProfChildCount; i++)
			{
				if (g_LastObjectLeftMouseDown == 6 + i + UO->m_UsedProfessionCategory->m_CatChildCount)
				{
					UO->m_UsedProfession = UO->m_UsedProfessionCategory->m_ProfChild[i];
					UO->m_UsedProfession->m_ScrollHeight = 0.0f;
					UO->m_UsedProfessionCategory = NULL;
					break;
				}
				OffsY += 79.0f;
			}
		}
	}
	else if (UO->m_UsedProfession != NULL)
	{
	}

	g_LastObjectLeftMouseDown = 0;
}
//---------------------------------------------------------------------------
void TCreateCharacterSelectionGump::ParseRightMouseDown()
{
}
//---------------------------------------------------------------------------
void TCreateCharacterSelectionGump::ParseRightMouseUp()
{
}
//---------------------------------------------------------------------------
bool TCreateCharacterSelectionGump::ParseLeftMouseDoubleClick()
{
	return false;
}
//---------------------------------------------------------------------------
bool TCreateCharacterSelectionGump::ParseRightMouseDoubleClick()
{
	return false;
}
//---------------------------------------------------------------------------
void TCreateCharacterSelectionGump::ParseMouseWheel(MOUSE_WHEEL_STATE state)
{
}
//---------------------------------------------------------------------------
void TCreateCharacterSelectionGump::ParseCharPress(WPARAM wparam, LPARAM lparam)
{
}
//---------------------------------------------------------------------------
void TCreateCharacterSelectionGump::ParseKeyPress(WPARAM wparam, LPARAM lparam)
{
}
//---------------------------------------------------------------------------